<?php

class log {

    static $CurrLogLevel = 'NOTICE';

    static public function warning($msg, $w = false, $p = true) {
        $msg = 'WARNING:' . $msg;
        self::$CurrLogLevel = 'WARNING';
        return logformat($msg, $w, $p);
    }

    public static function p($msg, $w = false, $p = true) {
        $s = date('Y-m-d H:i:s') . '|DEBUG:' . $msg . '|' . PHP_EOL;
        if ($w || DEFAULT_LOGLOG || (defined('UNDER_WEBSERVER') && defined('UNDER_WEBSERVER_ECHO_LOG'))) {
            $file = OUTPUT_LOGDIR . date('Y-m-d') . '.log';
            FcheckDir($file);
            file_put_contents($file, $s, 8);
        }
        if ($p || DEFAULT_ECHOLOG) {
            if (!defined('UNDER_WEBSERVER')) {
                echo $s;
            }
        }
    }

    static public function s($title, $html = '', $to = array('think889977@sina.com')) {
        if (!$html) {
            $html = $title . '<hr /><pre>' . print_r(debug_backtrace(), true);
        }
        return post_email($title, $html, $to);
    }

    static public function notice($msg, $w = false, $p = true) {
        $msg = 'NOTICE:' . $msg;
        self::$CurrLogLevel = 'NOTICE';
        return logformat($msg, $w, $p);
    }

    static public function error($msg, $w = false, $p = true) {
        $msg = 'ERROR:' . $msg;
        self::$CurrLogLevel = 'ERROR';
        if (defined('ERROR_EXIT') && !ERROR_EXIT) {
            return logformat($msg, $w, $p);
        } else {
            return die(logformat($msg, $w, $p));
        }
    }

    static public function w($msg, $w = false, $p = true) {
        return self::warning($msg, $w, $p);
    }

    static public function warn($msg, $w = false, $p = true) {
        return self::warning($msg, $w, $p);
    }

    static public function n($msg, $w = false, $p = true) {
        return self::notice($msg, $w, $p);
    }

    static public function e($msg, $w = false, $p = true) {
        return self::error($msg, $w, $p);
    }

    static public function dw($msg, $w = false, $p = true) {
        self::warning('====================ATTENTION===================', $w, $p);
        self::warning($msg, $w, $p);
        return self::warning('====================ATTENTION===================', $w, $p);
    }

}

?>